package com.rzx.mybackend.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzx.mybackend.common.PageResult;
import com.rzx.mybackend.dto.BuyGamePageDTO;
import com.rzx.mybackend.entity.BuyGames;
import com.rzx.mybackend.mapper.BuyGameMapper;
import com.rzx.mybackend.service.BuyGameService;
import com.rzx.mybackend.vo.BuyGamesVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * BuyGameServiceImpl
 *
 * @author renzhexian
 * @date 2025/7/22
 */
@Service
@RequiredArgsConstructor
public class BuyGameServiceImpl implements BuyGameService {

    private final BuyGameMapper buyGameMapper;

    /*
    购买游戏
     */
    @Override
    public void buyGames(BuyGames buyGames) {
        // TODO: 此处为购买逻辑
        buyGameMapper.insert(buyGames);

    }

    /*
    分页查询购买游戏列表
     */
    @Override
    public PageResult<BuyGamesVO> pageBuyGameList(BuyGamePageDTO buyGamePageDTO) {

        PageHelper.startPage(buyGamePageDTO.getPage(), buyGamePageDTO.getPageSize());

        Page<BuyGamesVO> buyGamesVOPage = buyGameMapper.page(buyGamePageDTO.getUserId());

        return new PageResult<>(buyGamesVOPage.getTotal(), buyGamesVOPage.getResult());
    }

}
